<?php

namespace App\Providers;

use App\Models\Orm\UserAuth;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;
use Laravel\Passport\Passport;
use Dusterio\LumenPassport\LumenPassport;
use Carbon\Carbon;
/**
 * @author qfh
 */
class AuthServiceProvider extends ServiceProvider
{

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Boot the authentication services for the application.
     *
     * @return void
     */
    public function boot()
    {
        /**
         *  Passport Config
         */
//        LumenPassport::allowMultipleTokens();
//        Passport::tokensExpireIn(Carbon::now()->addDays(15));
//        Passport::refreshTokensExpireIn(Carbon::now()->addDays(45));
        
        // Here you may define how you wish users to be authenticated for your Lumen
        // application. The callback which receives the incoming request instance
        // should return either a User instance or null. You're free to obtain
        // the User instance via an API token or any other method necessary.

        $this->app['auth']->viaRequest('api', function ($request) {
            $token = $request->input('token') ?: $request->header('X-Token');
            if ($token)
            {
                return UserAuth::where('accessToken', $token)->first();
            }
        });
    }

}
